package com.itheima.bos.active.consumer.queue;

import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.springframework.stereotype.Component;

import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.itheima.bos.utils.SmsDemoUtils;
@Component("queueConsumer")
public class QueueConsumer implements MessageListener{

	@Override
	public void onMessage(Message message) {
		MapMessage mapMessage = (MapMessage) message;
		try {
			String telephone = mapMessage.getString("telephone");
			String code = mapMessage.getString("code");
			SendSmsResponse response = SmsDemoUtils.sendSms(telephone, code);
			String result = response.getCode();
			if(result != null && "ok".equalsIgnoreCase(result)){
				System.out.println("短信发送成功...telephone:"+ telephone +",code:"+ code );
			}else{
				System.out.println("短信发送失败...");
			}
		} catch (Exception e) {
			System.out.println("短信发送失败...");
			e.printStackTrace();
		}
	}

	
}
